`
https://leetcode.cn/problems/minimum-removals-to-balance-array/
`

/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var minRemoval = function (nums, k) {
  // 等价于求最长的平衡子数组长度 len ，返回 n - len
  const n = nums.length
  nums.sort((a, b) => a - b)
  let res = 0
  let left = 0, right = 0

  while (right < n) {
    const n1 = nums[right++]
    // 缩小窗口
    while (nums[left] * k < n1) left++
    // 更新答案
    if (nums[left] * k >= n1) res = Math.max(res, right - left)
  }

  return n - res
};